package com.yadang.JsonDeserializer;
import com.fasterxml.jackson.databind.DeserializationFeature;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.dataformat.xml.XmlMapper;

import java.util.List;

public class XmlToJsonExample {
    public static void main(String[] args) throws Exception {
        String xmlString = "<Record>\n" +
                "            <BIZ_DATE>2023-03-19</BIZ_DATE>\n" +
                "            <BOND_ACCT>00000012647</BOND_ACCT>\n" +
                "            <BOND_ACCT_NAME_ABBR>矧猎洱袜并啮腰目卫</BOND_ACCT_NAME_ABBR>\n" +
                "            <BOND_CODE>180017</BOND_CODE>\n" +
                "            <BOND_NAME_ABBR>85募息钵草63</BOND_NAME_ABBR>\n" +
                "            <DENOMINATED_CURRENCY_DESC>人民币</DENOMINATED_CURRENCY_DESC>\n" +
                "            <SUBJ_SET>\n" +
                "                <BOND_SUBJ_NAME>可用</BOND_SUBJ_NAME>\n" +
                "                <SUBJ_FACE_AMNT>500</SUBJ_FACE_AMNT>\n" +
                "                <SUBJ_BAL_UNIT_DESC>万元</SUBJ_BAL_UNIT_DESC>\n" +
                "                <BOND_SUBJ_NAME>质权</BOND_SUBJ_NAME>\n" +
                "                <SUBJ_FACE_AMNT>600</SUBJ_FACE_AMNT>\n" +
                "                <SUBJ_BAL_UNIT_DESC>万元</SUBJ_BAL_UNIT_DESC>\n" +
                "            </SUBJ_SET>\n" +
                "        </Record>";

        XmlMapper xmlMapper = new XmlMapper();
        JsonNode rootNode = xmlMapper.readTree(xmlString.getBytes());

        String jsonString = rootNode.toString();
        System.out.println(jsonString);

        ObjectMapper mapper = new ObjectMapper();
        mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
        Record record = mapper.readValue(jsonString, Record.class);
        System.out.println(record.toString());
    }
}
